package com.example.springboot.controller.数据库;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.sql.DataSource;

/**
 * 整合第三方技术的两种方式
 *    ● 自定义
 *    ● 找starter
 *
 * 自动配置
 * ● 扩展配置项 spring.datasource.druid
 * ● DruidSpringAopConfiguration.class
 *     监控SpringBean的；配置项：spring.datasource.druid.aop-patterns
 * ● DruidStatViewServletConfiguration.class
 *    监控页的配置：spring.datasource.druid.stat-view-servlet；默认开启
 * ●  DruidWebStatFilterConfiguration.class
 *    web监控配置；spring.datasource.druid.web-stat-filter；默认开启
 * ● DruidFilterConfiguration.class})
 *    所有Druid自己filter的配置
 *
 */
@Slf4j
@Controller
public class 引入数据源 {//https://github.com/alibaba/druid 源码在这

    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    DataSource dataSource;

    @GetMapping("/MyDataSourceConfig")
    public String myDataSourceConfig() {
        Long aLong = jdbcTemplate.queryForObject("select count(*) from user_long", Long.class);
        log.info("记录总数:" + aLong);
        log.info("数据源类型:{}",dataSource.getClass());
        return "login";
    }
}

